﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hisun.Controllers;
using Hisun.Models;

namespace Hisun.UserControl.CostCenterItem
{
    /// <summary>
    /// 
    /// Copyright (C) 2008 HOHO``
    /// All rights reserved
    /// NameSpace:Hisun.UserControl.CostCenterItem.List
    /// Description :
    /// Created By QiuZhongJie At 2008/10/17 18:23
    /// </summary>
    public partial class List : System.Web.UI.UserControl
    {
        private string costItemBrevityCode;//成本细项简码

        public string CostItemBrevityCode
        {
            get { return costItemBrevityCode; }
            set { costItemBrevityCode = value; }
        }

        private string accountPeriod;//会计时间

        public string AccountPeriod
        {
            get { return accountPeriod; }
            set { accountPeriod = value; }
        }

        private bool canEdit;//是否允许编辑

        public bool CanEdit
        {
            get { return canEdit; }
            set { canEdit = value; }
        }

        //private Parameter paramCostItemsID;//成本细项
        //private Parameter paramAccountPeriod;//会计期间
        private Parameter paramCustom;//自设定

        public Parameter ParamCustom
        {
            get { return paramCustom; }
            set { paramCustom = value; }
        }




        /// <summary>
        /// Initializes a new instance of the <see cref="List"/> class.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public List()
        {
            canEdit = false;
        }

        public void SetSearchKey(Parameter p)
        {

            if (LinqDataSource1.WhereParameters.Count > 2)
                LinqDataSource1.WhereParameters.RemoveAt(2);
            if (p == null)
            {
                labMsg.Text = "没有找到相关的记录";
                return;
            }
            LinqDataSource1.WhereParameters.Add(p);
            paramCustom = p;
            try
            {
                GridView1.DataBind();
            }
            catch(Exception ex)
            {
                Response.Write(string.Format("输入的查询值格式有误或者无法转换,请检查输入.详细信息:{0}",ex.Message));
                Response.End();
            }
        }

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (costItemBrevityCode == null || accountPeriod == null)
                throw new Exception("遇到致命错误！由于安全问题，操作终止！请联系系统管理员．");
            labMsg.Text = string.Empty;
            if (LinqDataSource1.WhereParameters.Count < 2)
            {
                LinqDataSource1.WhereParameters.Add("成本细项ID", costItemBrevityCode);
                LinqDataSource1.WhereParameters.Add("会计期间ID", accountPeriod);
            }
        }

    }
}